from __future__ import absolute_import

from scopt.util import message as msg_util
from scopt.util.message_types import STRING
from . import message
from scopt.mpu.business.db import transaction


@message(type='devel.echo',
         version='0.1',
         note='devel.echo version 0.1 is deprecated. Use version 0.2 instead',
         reqd={'text': STRING(required=True)},
         resd={'text': STRING(required=True)})
@transaction(['lds/BDS'])
def echo(data_packet):
    reqd = msg_util.get_request_data(data_packet)
    text = reqd['text']
    response = echo.RESPONSE()
    resd = response['resd']
    resd['text'] = '0.1: ' + text
    return msg_util.ok_response(data_packet, echo, resd)


@message(type='devel.echo',
         version='0.2',
         reqd={'text': STRING(required=True)},
         resd={'text': STRING(required=True)})
def echo2(data_packet):
    reqd = msg_util.get_request_data(data_packet)
    text = reqd['text']
    response = echo2.RESPONSE()
    resd = response['resd']
    resd['text'] = '0.2: ' + text
    return msg_util.ok_response(data_packet, echo2, resd)
